//
// Created by ZLY on 2025/3/29.
//

#ifndef DEMUXTHREAD_H
#define DEMUXTHREAD_H
#include <string>
#include "AVPacketQueue.h"
#include "thread.h"
#include "Log.h"
extern "C" {
#include <libavformat/avformat.h>
}

class DemuxThread : public Thread {
public:
    DemuxThread(AVPacketQueue *audio_queue, AVPacketQueue *video_queue);

    ~DemuxThread();

    int Init(const char *url);

    int Start();

    int Stop();

    void Run();

    AVCodecParameters *AudioCodecParameters();

    AVCodecParameters *VideoCodecParameters();

private:
    char err2str[255] = {0};
    std::string url_;
    AVPacketQueue *audio_queue_ = nullptr;
    AVPacketQueue *video_queue_ = nullptr;
    AVFormatContext *fmt_ctx_ = nullptr;
    int audio_index_ = -1;
    int video_index_ = -1;
};


#endif //DEMUXTHREAD_H
